<!--
- File:    共享花园的子花园列表.
-->
<template>
  <div>
    <div class="Web_Box">
      <div class="g_teams f-cb" v-show="isCreator == '1'">
        <a class="team_btn" @click="gotoAddDistributeFansList">添加园丁</a><a class="team_btn" @click="gotoDistributeMemberList">所有园丁</a>
      </div>
      <div class="Release2 f-cb pl20 tc" v-show="isCreator == '1'">
        <a class="rbtn" @click="showGardenSheet"><i class="iconfont icon-bianji"></i>编辑花园</a>
      </div>
      <div class="graden_cont" v-for="item in shareGardenList.data" @click="gotoGardenChildDetail(item, 'false')">
        <ul class="f-cb">
          <li class="mood_graden">
            <a><img :src="(!item.cover_img || item.cover_img == '') ? defaultGardenImg :($config.imgsite + $config.uploadImgSrc + item.cover_img + '_w200') ">
            </a>
          <span class="num-notice"  @click="gotoGardenChildDetail(item, 'true')" v-show="item.hastask_flower_num && item.hastask_flower_num > 0">{{item.hastask_flower_num}}</span>
          </li>
          <li><a>
            <div class="graden_bg">
              <h3>{{item.garden_name}}({{item.flower_num}}) <span style="color: #aaa; font-size: 12px;">(编号:{{item.sg_id}}-{{item.g_id}})</span></h3>
              <p>{{item.city_name}}</p>
              <!--<p>创建时间：{{item.add_time}}</p>-->
            </div>
          </a></li>
        </ul>
      </div>
      <div v-show="shareGardenList.requested && shareGardenList.data.length <= 0" style="height: 3rem; line-height: 3rem; background: #fff; text-align: center;margin-bottom: 0.5rem">
        当前没有区域花园~
      </div>
      <div class="add_gran f-cb" v-show="isCreator == '1'">
        <a @click="gotoAddChildGarden" class="add_btn2">新建区域花园</a>
        <router-link :to="{name: 'garden-child-deleted', query: {parentId: parentId}}"><a class="add_btn3">已删除的区域花园</a>
        </router-link>
      </div>
      <!--<div class="bg_fff"><a class="ency_btn" @click="delParentGarden" v-show="isCreator == '1'">删除花园</a></div>-->
    </div>
    <!--<div class="Photograph"><a href="index.html"><i class="iconfont icon-app-index-a"></i></a></div>-->
    <footer-tab></footer-tab>
    <mt-actionsheet
      :actions="gardenActions"
      v-model="gardenSheetVisible">
    </mt-actionsheet>
  </div>
</template>

<script>
  import {Swipe, SwipeItem, Actionsheet} from 'mint-ui'

  export default{
    data() {
      return {
        parentId: this.$route.query.parentId,
        isCreator: this.$route.query.isCreator, // 0 非创建者， 1 创建者
        defaultGardenImg: require('../../../assets/images/demo/xinqing.png'),
        shareGardenList: {requested: false, loading: false, page: 1, pageSize: 10, data: []},
        gardenSheetVisible: false,
        gardenActions: [{
          name: '修改信息',
          method: this.updateParentGarden
        }, {
          name: '删除花园',
          method: this.delParentGarden
        }]
      }
    },
    components: {
      'mtSwipe': Swipe,
      'mtSwipeItem': SwipeItem,
      'mt-actionsheet': Actionsheet
    },
    created() {
      this.getShareGardenChildrenList(this.shareGardenList.page, this.shareGardenList.pageSize)
    },
    methods: {
      gotoAddChildGarden() {
        this.$router.push({name: 'garden-child-add', query: {parentId: this.parentId}})
      },
      showGardenSheet() {
        this.gardenSheetVisible = true
      },
      gotoAddDistributeFansList() {
        this.$router.push({name: 'distribute-fans', query: {garden: this.parentId}})
      },
      gotoDistributeMemberList() {
        this.$router.push({name: 'distribute-member', query: {garden: this.parentId}})
      },
      // isDefault 是否是默认花园（心情花园）
      gotoGardenChildDetail(garden, taskVisible) {
        this.$router.push({
          name: 'garden-detail',
          params: {id: garden.g_id},
          query: {
            isDefault: 'false', // 非心情花园
            gardenType: this.$dictionary.gardenType.share, // 是共享花园
            parentId: this.parentId,
            isCreator: this.isCreator,
            areaId: garden.area_id,
            areaName: garden.area_id ? garden.city_name + ' ' + garden.area_name : undefined,
            title: this.$route.query.title + '-' + garden.garden_name,
            taskVisible: taskVisible
          }
        })
      },
      getShareGardenChildrenList() {
        this.shareGardenList.loading = true
        this.$request.getShareGardenChildrenList(this.parentId).then(data => {
          this.shareGardenList.data = [...this.shareGardenList.data, ...data]
        }).finally(() => {
          this.shareGardenList.requested = true
          this.shareGardenList.loading = false
        })
      },
      updateParentGarden() {
        this.$router.push({name: 'garden-share-Edit', params: {id: this.parentId}})
      },
      delParentGarden() {
        this.$messageBox.confirm('确定删除？').then(data => {
          this.$request.delShareGarden(this.parentId).then(data => {
            this.$toast('删除成功')
            this.$router.go(-1)
          }).catch(e => {
            this.$toast('删除失败:' + e.msg)
          })
        }).catch(() => {
        })
      }
    }
  }
</script>

<style>

</style>